//
//  SFTitleButton.swift
//  SFWeiboPro
//
//  Created by happy on 2017/9/20.
//  Copyright © 2017年 happy. All rights reserved.
//

import UIKit

class SFTitleButton: UIButton {

    init(title: String?) {
        super.init(frame: CGRect())
        
        if title == nil {
            setTitle("首页", for: [])
        }
        else{
            setTitle((title! + " "), for: [])
            setImage(UIImage.init(named: "navigationbar_arrow_down"), for: [])
            setImage(UIImage.init(named: "navigationbar_arrow_up"), for: .selected)
        }
        
        titleLabel?.font = UIFont.boldSystemFont(ofSize: 17.0)
        setTitleColor(UIColor.darkGray, for: [])
        
        sizeToFit()
        
//        self.backgroundColor = UIColor.red
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        guard let titleLabel = titleLabel, let imageView = imageView else {
            return
        }
        
        print("titleLabel = \(titleLabel), imageView = \(imageView)")
        
        titleLabel.yw_left = 0
        
        imageView.yw_left = titleLabel.bounds.width
        
//        titleLabel.frame = titleLabel.frame.offsetBy(dx: -imageView.bounds.width, dy: 0)
//        
//        imageView.frame = imageView.frame.offsetBy(dx: titleLabel.bounds.width, dy: 0)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
